package com.example.utils.cos;

public class FileContentTypeUtils {

    public static String contentType(String suffix) {
        if(suffix == null) {
            return null;
        }
        suffix = suffix.toLowerCase();
        if (suffix.endsWith(".jpeg") || suffix.endsWith(".jpg") || suffix.endsWith(".png")) {
            return "image/jpeg";
        }
        if(suffix.endsWith(".tif")) {
            return "image/tiff";
        }
        if (suffix.endsWith(".bmp")) {
            return "image/bmp";
        }
        if (suffix.endsWith(".gif")) {
            return "image/gif";
        }
        if (suffix.endsWith(".html")) {
            return "text/html";
        }
        if (suffix.endsWith(".txt")) {
            return "text/plain";
        }
        if (suffix.endsWith(".vsd")) {
            return "application/vnd.visio";
        }
        if (suffix.endsWith(".pptx") || suffix.endsWith(".ppt")) {
            return "application/vnd.ms-powerpoint";
        }
        if (suffix.endsWith(".docx") || suffix.endsWith(".doc")) {
            return "application/msword";
        }
        if (suffix.endsWith(".xml")) {
            return "text/xml";
        }
        if (suffix.endsWith(".pdf")) {
            return "application/pdf";
        }

        return null;
    }

    public static String imgTypeValid(String dataPrix) {
        if ("data:image/jpeg;".equalsIgnoreCase(dataPrix)) {
            return ".jpeg";
        } else if ("data:image/jpg;".equalsIgnoreCase(dataPrix)) {
            return ".jpg";
        } else if ("data:image/gif;".equalsIgnoreCase(dataPrix)) {
            return ".gif";
        } else if ("data:image/png;".equalsIgnoreCase(dataPrix)) {
            return ".png";
        } else if ("data:image/apng;".equalsIgnoreCase(dataPrix)) {
            return ".apng";
        } else if ("data:image/svg;".equalsIgnoreCase(dataPrix)) {
            return ".svg";
        } else if ("data:image/bmp;".equalsIgnoreCase(dataPrix)) {
            return ".bmp";
        }
        return null;
    }

    public static String fileTypeValid(String dataPrix) {
        if ("data:text/plain;".equalsIgnoreCase(dataPrix)) {
            return ".txt";
        }
        return null;
    }
}
